/*
 * Course:    CS 590 Web Services
 * Semseter:  Spring 2009
 * Professor: Sedlemeyer
 * Project:   CHEAT (Code Help Educational Assignment Tool)
 * Due Date:  May 1, 2009
 * Team:      Sarcasm
 *            (Baker, Jason; Mitchell, Robin; Shie, Keith)
 */

package cheat.entities;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

/**
 * Defines a course which may be associated with an assignment.
 *
 * @author Keith Shie
 */
@Entity
@Table(name = "course")
@NamedQueries({@NamedQuery(name = "Course.findAll", query = "SELECT c FROM Course c"),
        @NamedQuery(name = "Course.findByCourseId", query = "SELECT c FROM Course c WHERE c.courseId = :courseId"),
        @NamedQuery(name = "Course.findByCourseLabel", query =
        "SELECT c FROM Course c WHERE c.label = :label")})
public class Course implements Serializable {
  private static final long serialVersionUID = 1L;
  @Id
  @Basic(optional = false)
  @Column(name = "course_id", nullable = false)
  @SequenceGenerator(name="course_seq", sequenceName="course_course_id_seq", allocationSize=1)
  @GeneratedValue( strategy=GenerationType.SEQUENCE,generator="course_seq")
  private Integer courseId;
  @Basic(optional = false)
  @Column(name = "course_label", nullable = false, length = 10)
  private String label;
  @Column(name = "course_desc", length = 50)
  private String description;
  @ManyToMany(mappedBy = "courseCollection",fetch=FetchType.LAZY)
  private Collection<AssignmentProperty> assignmentPropertyCollection;


  public Course() {
  }


  public Course( Integer courseId ) {
    this.courseId = courseId;
  }


  public Course( Integer courseId, String courseLabel ) {
    this.courseId = courseId;
    this.label = courseLabel;
  }


  public Integer getCourseId() {
    return courseId;
  }


  public void setCourseId( Integer courseId ) {
    this.courseId = courseId;
  }


  public String getLabel() {
    return label;
  }


  public void setLabel( String label ) {
    this.label = label;
  }


  public String getDescription() {
    return description;
  }


  public void setDescription( String description ) {
    this.description = description;
  }


  public Collection<AssignmentProperty> getAssignmentPropertyCollection() {
    return assignmentPropertyCollection;
  }


  public void setAssignmentPropertyCollection( Collection<AssignmentProperty> assignmentPropertyCollection ) {
    this.assignmentPropertyCollection = assignmentPropertyCollection;
  }


  @Override
  public int hashCode() {
    int hash = 0;
    hash += (courseId != null ? courseId.hashCode() : 0);
    return hash;
  }


  @Override
  public boolean equals( Object object ) {
    // TODO: Warning - this method won't work in the case the id fields are not set
    if (!(object instanceof Course)) {
      return false;
    }
    Course other = (Course) object;
    if ((this.courseId == null && other.courseId != null) || (this.courseId != null && !this.courseId.equals( other.courseId ))) {
      return false;
    }
    return true;
  }


  @Override
  public String toString() {
    return "entities.Course[courseId=" + courseId + "]";
  }

}
